<template>
	<view>
		<img src="/static/login/jiaopian.png" class="bg" />
		<img src="/static/login/logo.png" class="logo" />
		<!-- #ifdef H5  -->
		<view class="form">
			<view class="form_phone">
				<view class="form_phone_field">手机号</view>
				<input class="form_phone_input" type="number" maxlength="11" />
			</view>
			<view class="form_code">
				<view class="form_code_field">验证码</view>
				<input class="form_code_input" type="number" maxlength="4" />
				<view class="form_code_btn">发送验证码</view>
			</view>
			<view class="form_btn">
				<text class="form_btn_text">立即提交</text>
			</view>
		</view>
		<!-- #endif -->
		<view class="btn">
			<button style="position: absolute; width: 100%;height: 100%;background: red;opacity: 0;"
			open-type="getPhoneNumber" @getphonenumber="getphonenumber"
			></button>
			<text class="btn_text">一键手机号授权</text>
		</view>
	</view>
</template>

<script>
import Login from '../../utils/login.js';
import Route from '../../utils/route.js';
export default {
	data() {
		return {};
	},
	async onLoad() {
		// 小程序获取Openid
		// #ifdef MP-WEIXIN
		let res = await Route.login_wechat_openid({
			code: await Login.getCode()
		});
		this.openid = res.openid;
		this.session_key = res.session_key;
		uni.setStorageSync('openid', res.openid);
		uni.setStorageSync('session_key', res.session_key);
		// #endif
	},
	methods: {
		// 获取手机号
		async getphonenumber(e){
			let res = await Route.login_wechat_phone({
				uid:uni.getStorageSync('userInfo').uid,
				openid:uni.getStorageSync('openid'),
				session_key:uni.getStorageSync('session_key'),
				encryptedData:e.detail.encryptedData,
				iv:e.detail.iv,
			})
			uni.setStorageSync('phone',res.phone)
			uni.navigateBack()
		}
	}
};
</script>

<style lang="scss">
page {
	background: $template-background;
}
.bg {
	position: absolute;
	width: 750rpx;
	height: 1095rpx;
}
.logo {
	position: absolute;
	left: 0;
	right: 0;
	top: 81rpx;
	margin: auto;
	width: 300rpx;
	height: 300rpx;
}
.form {
	position: absolute;
	top: 333rpx;
	left: 0;
	right: 0;
	margin: auto;
	width: 600rpx;
	padding: 30rpx;
	background: rgba($color: #fff, $alpha: 0.8);
	border-radius: 16rpx;
	&_phone {
		display: flex;
		align-items: center;
		padding: 33rpx;
		background: #fff;
		&_field {
			width: 108rpx;
			font-size: $uni-font-size-base;
		}
		&_input {
			padding: 16rpx;
			width: 450rpx;
			border: 1rpx solid $template-line;
		}
	}
	&_code {
		display: flex;
		align-items: center;
		padding: 16rpx 33rpx;
		background: #fff;
		&_field {
			width: 108rpx;
			font-size: $uni-font-size-base;
		}
		&_input {
			padding: 16rpx;
			width: 111rpx;
			border: 1rpx solid $template-line;
		}
		&_btn{
			font-size: $uni-font-size-base;
			width: 166rpx;
			padding: 16rpx;
			background: #04be02;
			color: #fff;
			text-align: center;
			border-radius: 33rpx;
			margin-left: 66rpx;
		}
	}
	&_btn{
		padding-top: 33rpx;
		padding-bottom: 33rpx;
		background: #fff;
		display: flex;
		justify-content: center;
		&_text{
			font-size: $uni-font-size-base;
			width: 188rpx;
			padding: 20rpx;
			background: #04be02;
			color: #fff;
			text-align: center;
			border-radius: 33rpx;
			margin-bottom: 16rpx;
		}
	}
}
.btn {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 333rpx;
	margin: auto;
	background: #04be02;
	color: #fff;
	font-size: 32rpx;
	font-weight: 600;
	width: 490rpx;
	height: 81rpx;
	text-align: center;
	line-height: 81rpx;
	border-radius: 33rpx;
	display: flex;
	justify-content: center;
	&_text {
		margin-left: 8rpx;
	}
}
</style>
